<?php
/**
 * Created by PhpStorm.
 * User: Kevin
 * Date: 2018/7/2
 * Time: 11:04
 */
namespace app\admin\controller;
use \think\Request;
use think\Db;
class About extends Base
{
    protected $res = array(
        'index'   => array('css' => '2,3,4', 'js' => 'list'),
        'edit'   => array('css' => '2,3,4,5,9', 'js' => 'ueditor_config,ueditor_all,ueditor_lang'),
    );
    /**
     * 首页数据
     * @return mixed
     */
    public function index(){
        $list = Db::table('up_about_us')
            ->field('a_id,a_logo,a_appname,a_version,a_introduce,a_company_name')
            ->select();
        $action = '/' . Request::instance()->controller() . '/' . Request::instance()->action();
        $this->assign ([
            'list'=>$list,
            'action'=>$action,
        ]);
        return $this->fetch();
    }

    /**
     * 修改
     * @return mixed
     */
    public function edit(){
        $id = input('id');
        if(request()->isAjax ()){
            extract(input());
            if($appname == "" ){
                return $this->api_error('App名称不能为空', '14001');
            }
            if($version == ""){
                return $this->api_error('版本号不能为空', '14001');
            }
            if($content == ''){
                return $this->api_error('内容不能为空', '14001');
            }
            if($_FILES['file']['name'][0]!='') {
                $info = $this->uploadFile($_FILES);
//               if($info['status']!=200) {
//                   return $this->api_dbError("上传文件格式不正确");
//               }
                $param['a_logo'] =$info;

            }
            $param['a_appname'] = $appname;
            $param['a_version'] = $version;
            $param['a_introduce'] = $content;
            $param['a_update_time'] = date('Y-m-d H:i:s');
            $res = Db::table('up_about_us')->where('a_id',$aid)->update($param);
            if ($res) {
                return $this->api_success("操作成功");
            } else {
                return $this->api_dbError("操作失败");
            }
        }
        $list = Db::table('up_about_us')
            ->where('a_id',$id)
            ->field('a_id,a_logo,a_appname,a_version,a_introduce,a_company_name')
            ->find();
        $this->assign ('data',$list);
        return $this->fetch('edit');
    }
}